package com.haruhi.example;

import com.haruhi.event.MessageConsumer;
import com.haruhi.ws.server.ServerEndpointManager;

import javax.servlet.ServletException;
import java.io.IOException;

public class ServerStart {
    public static void main(String[] args) throws IOException, ServletException, ClassNotFoundException {
        method2(); //看这个 使用方式
    }
    public static void method2() throws IOException, ServletException, ClassNotFoundException {
        MessageConsumer.start("com.haruhi.example");
        ServerEndpointManager endpointManager = ServerEndpointManager.builder()
                .setContextPath("/haruhi")
                // 通过端口区分每一个ws服务端
                .addServerEndpoint(8999, "/ws/test3")
                .addServerEndpoint(8899, "/ws/test4",new MyHandshakeInterceptor())
                .addServerEndpoint(8900, "/ws/test1",new MyServerEndpoint())//自定义ServerEndpoint
                .addServerEndpoint(8911, "/ws/test2",new MyServerEndpoint(),new MyHandshakeInterceptor())//添加握手拦截器
                .build();
        endpointManager.start();
        try {
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 关闭某一个服务端
        endpointManager.stop(8999);

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 再开启某一个服务端
        endpointManager.start(8999);

    }
}
